<?php
class LogController extends AdminBaseController {

    public function role(){
        $this->common('role', '创建角色日志');
    }

    public function feedback(){
        $this->common('feedback', '反馈日志表');
    }

    public function fightpve(){
        $this->common('fightpve', '战斗日志表PVE');
    }

    public function fightpvp(){
        $this->common('fightpvp', '战斗日志表PVP');
    }

    public function gamebox(){
        $this->common('gamebox', '宝箱日志');
    }


    public function goods(){
        $this->common('goods', '道具日志');
    }

    public function gold(){
        $this->common('gold', '货币日志');
    }

    public function pet(){
        $this->common('pet', '宠物日志');
    }

    public function petoper(){
        $this->common('petoper', '宠物操作日志');
    }

    public function activity(){
        $this->common('activity', '玩家活动日志');
    }

    public function friend(){
        $this->common('friend', '添加好友日志');
    }

    public function logout(){
        $this->common('logout', '玩家登出日志');
    }

    public function login(){
        $this->common('login', '玩家登陆日志');
    }

    public function orders(){
        $this->common('orders', '玩家充值日志');
    }

    public function reg(){
        $this->common('reg', '玩家注册日志');
    }

    public function shop(){
        $this->common('shop', '商城购买日志');
    }

    public function task(){
        $this->common('task', '玩家任务日志');
    }

    public function singing(){
        $this->common('singing', '签到日志');
    }

    public function online(){
        $this->common('online', '在线日志');
    }

    public function level(){
        $this->common('level', '玩家升级日志');
    }

    public function activityPro(){
        $this->common('activityPro', '玩家活动参与日志');
    }

    public function alarm(){
        $this->common('alarm', '物品操作告警日志');
    }

    public function payLogin(){
        $this->common('payLogin', '付费用户登录日志');
    }

    public function equipattr(){
        $this->common('equipattr', '装备炼化日志');
    }

    public function equipskill(){
        $this->common('equipskill', '装备技能重置日志');
    }

    public function equipRecattrf(){
        $this->common('equipRecattrf', '装备属性洗练');
    }

    public function rolePatrol(){
        $this->common('rolePatrol', '自动挂机日志');
    }

    public function blackMarket(){
        $this->common('blackMarket', '神秘商店日志');
    }

    public function partnerFight(){
        $this->common('partnerFight', '伙伴数据日志');
    }

    public function redeemCode(){
        $this->common('redeemCode', '兑换码领取日志');
    }

    public function email(){
        $this->common('email', '邮件日志');
    }
    
    public function bossFall(){
    	$this->common('bossFall', 'Boss掉落日志');
    }
    
    public function pickup(){
    	$this->common('pickup', 'Boss掉落拾取日志');
    }
    
    public function bossDeath(){
    	$this->common('bossDeath', 'Boss死亡记录日志');
    }
    
    public function equWear(){
    	$this->common('equWear', '装备穿戴日志');
    }
    
    public function equSuit(){
    	$this->common('equSuit', '装备套装日志');
    }
    
    public function soulUpgrade(){
    	$this->common('soulUpgrade', '聚魂升级日志');
    }
    
    public function stateUpgrade(){
    	$this->common('stateUpgrade', '境界提升日志');
    }
    
    public function fashionUpgrade(){
    	$this->common('fashionUpgrade', '时装提升日志');
    }
    
    public function swordUpgrade(){
    	$this->common('swordUpgrade', '剑魂提升日志');
    }
    
    public function daily(){
    	$this->common('daily', '日常经验日志');
    }
    
    public function sports(){
    	$this->common('sports', '竞技场日志');
    }
    
    public function sendcoin(){
    	$this->common('sendcoin', '充值发放日志');
    }
    
    public function instEnter(){
    	$this->common('instEnter', '副本进入日志');
    }
    
    public function instExit(){
    	$this->common('instExit', '副本退出日志');
    }
    
    public function achievement(){
    	$this->common('achievement', '成就达成日志');
    }
    
    public function compose(){
    	$this->common('compose', '合成日志');
    }
    
    public function equipSell(){
    	$this->common('equipSell', '玩家装备出售日志');
    }
    
    public function equipSwallow(){
    	$this->common('equipSwallow', '玩家装备吞噬日志');
    }
    
    public function guildCreate(){
    	$this->common('guildCreate', '帮派创建日志');
    }
    
    public function guildCapital(){
    	$this->common('guildCapital', '帮派资金日志');
    }
    
    public function guildLevelup(){
    	$this->common('guildLevelup', '帮派等级日志');
    }
    
    public function guildMember(){
    	$this->common('guildMember', '帮派成员日志');
    }
    
    public function guildRedpacket(){
    	$this->common('guildRedpacket', '帮派红包日志');
    }
    
    public function slotStrengthen(){
    	$this->common('slotStrengthen', '玩家各部位强化日志');
    }
    
    public function equipWear(){
    	$this->common('equipWear', '装备穿戴日志');
    }
    
    public function equipInlay(){
    	$this->common('equipInlay', '装备镶嵌日志');
    }
    
    public function equipSuit(){
    	$this->common('equipSuit', '装备套装日志');
    }
    
    public function rank(){
    	$this->common('rank', '排行榜日志');
    	$this->out['is_his'] = 1;
    }
    
    public function runeUpgrade(){
    	$this->common('runeUpgrade', '符文升级日志');
    }
    
    public function giftUse(){
    	$this->common('giftUse', '礼包使用日志');
    }   
    
    public function appearanceUpgrade(){
    	$this->common('appearanceUpgrade', '外观类升级日志');
    }
    
    public function shapeOpen(){
    	$this->common('shapeOpen', '外观类幻形激活日志');
    }
    
    public function shapeUpgrade(){
    	$this->common('shapeUpgrade', '外观类幻形升级日志');
    }
    
    public function shapeDecompose(){
    	$this->common('shapeDecompose', '外观类幻形分解日志');
    }

    public function market(){
    	$this->common('market', '市场日志');
    }
    
    
    public function test(){
    	$data = array(
    			array('type'=>'role','name'=>'角色日志'),
    			array('type'=>'login','name'=>'登录日志'),
    	);
    	$this->muchcommon($data,'日志');
    	
    	//同时需要定义role()方法、login()方法
    }
    
    
    public function faction(){
    	$data = array(
    			array('type'=>'factionMember','name'=>'帮派成员日志'),
    			array('type'=>'factionGrade','name'=>'帮派等级日志'),
    			array('type'=>'factionCapital','name'=>'帮派资金日志'),
    			array('type'=>'factionRedpacket','name'=>'帮派红包日志'),
    	);
    	$this->muchcommon($data,'帮派日志');
    }
    
    public function factionMember(){
    	$this->common('factionMember', '帮派成员日志');
    }
    
    public function factionGrade(){
    	$this->common('factionGrade', '帮派等级日志');
    }
    
    public function factionCapital(){
    	$this->common('factionCapital', '帮派资金日志');
    }
    
    public function factionRedpacket(){
    	$this->common('factionRedpacket', '帮派红包日志');
    }
    
    public function surface(){
    	$data = array(
    			array('type'=>'surfaceWing','name'=>'翅膀类外观'),
    			array('type'=>'unrealWing','name'=>'翅膀类外观幻形'),
    			array('type'=>'surfaceMounts','name'=>'坐骑类外观'),
    			array('type'=>'unrealMounts','name'=>'坐骑类外观幻形'),
    	);
    	$this->muchcommon($data,'外观日志');
    }
    
    public function surfaceWing(){
    	$this->common('surfaceWing', '翅膀类外观');
    }
    
    public function unrealWing(){
    	$this->common('unrealWing', '翅膀类外观幻形');
    }
    
    public function surfaceMounts(){
    	$this->common('surfaceMounts', '坐骑类外观');
    }
    
    public function unrealMounts(){
    	$this->common('unrealMounts', '坐骑类外观幻形');
    }

    
    private function muchcommon($data,$title){
        $filter = new PubFilter();
        $grid = new PubGrid();

        $filter->addOsFilter();
        $filter->addServerFilter(false)
            ->addPort()
            ->addFilter('time', 'timerange', PubFunc::t('时间'), array('min' => '2018.01.01', 'value' => PubDateRange::getLastDayRange(2, false, strtotime('2018-01-01'))))
            ->addFilter('faction_name', 'input', '帮派名称')
            ->addExport();

        $this->setTitle($title);
        $params = $filter->get();
        
        
        $options = PubAuthSession::get('os');
        $os_array = array();
        foreach ($options as $key=>$val){
        	$os_array[] = $key;
        }
        if(!in_array($params['os'], $os_array)){
        	unset($params['os']);
        }
        
        $order  = 'ctime';
        
        foreach ($data as $key=>$val){
        	$header = LogService::header($val['type']);
        	$url = PubFunc::ajaxUrl("?r=log/{$val['type']}", $params);
        	$grid->addGrid($header, $url, array(
        			'name'=>$val['name'],
        			'order'=>array($order, 'desc'),
        			'type'=>'log/'.$val['type']
        	));
        }
        
        $this->out['grid'] = $grid->show();
        $this->out['filter'] = $filter->show();
        $this->tpl = 'log.tpl'; 
        
        $this->out['ajax_search'] = 1;
    	
    }

    private function common($type, $title){
        $filter = new PubFilter();
        $grid = new PubGrid();

        $header = LogService::header($type);
        
        $lod_special_id = $this->R('special_id');
        $lodos = $this->R('os');
        $filter->addSpecialFilter(false,1);
        $filter->addOsFilter($lod_special_id,true,1);
        $filter->addServerFilter($lod_special_id,$lodos,false,false,1)
            ->addPort(1)
            ->addFilter('time', 'timerange', PubFunc::t('时间'), array('min' => '2018.01.01', 'value' => PubDateRange::getLastDayRange(6, false, strtotime('2018-01-01'))),1)
            ->addFilter('roleid', 'input', '角色ID')
            ->addFilter('openid', 'input', '平台用户ID')
            ->addExport();
        
        if(isset($header['rolename'])){
        	$filter->addFilter('rolename', 'input', '角色名');
        }
        
        if($type == 'gold'){
        	$filter->addCoin(true);
        	$filter->addAccess('way',true);
        	$filter->addStreamType(true);
        }
        
        if($type == 'bossFall' || $type == 'pickup'){
        	$filter->addFilter('boosid', 'input', 'Boss ID');
        	//$filter->addFilter('boos_name', 'input', 'Boss名字');
        	$filter->addFilter('item_id', 'input', '物品 ID');       	
        } 

        if($type == 'bossDeath'){
        	$filter->addFilter('boosid', 'input', 'Boss ID');
        }
        
        if($type == 'task'){
        	$filter->addFilter('task_id', 'input', '任务ID');
        }
        
        if($type == 'goods'){
        	$filter->addFilter('goods_id', 'input', '物品ID');
        	$filter->addFilter('goods_name', 'input', '物品名称');
        	$filter->addAccess('goods_access',true);
        	$filter->addStreamType(true);
        	
        	$colorType = LogService::getcolorType();
        	$colorType = array('' => '所有') + $colorType;
        	$filter->addFilter('g_quality', 'select', PubFunc::t('物品品质'), array('options' => $colorType, 'value' => key($colorType)));
        	$filter->addFilter('g_stage', 'input', '物品阶数');
        	$filter->addFilter('g_star', 'input', '物品星级');
        }
        
        if($type == 'shop'){
        	$filter->addFilter('goods_id', 'input', '物品ID');
        	
        	//物品品质帅选
        	$colorType = LogService::getcolorType();
        	$colorType = array('' => '所有') + $colorType;
        	$filter->addFilter('g_quality', 'select', PubFunc::t('物品品质'), array('options' => $colorType, 'value' => key($colorType)));
        	$filter->addFilter('g_g_name', 'input', '物品名称');
        	$filter->addFilter('g_stage', 'input', '物品阶数');
        	$filter->addFilter('g_star', 'input', '物品星级');
        }
        
        if($type == 'appearanceUpgrade' || $type == 'shapeOpen' || $type == 'shapeUpgrade' || $type == 'shapeDecompose'){
        	$filter->addAppearanceType(true);
        }       
        
        
        if($type == 'instEnter' || $type == 'instExit'){
        	$filter->addInstType(true);
        	//$filter->addInstMap(true);
        }
        
        if($type == 'guildCapital'){
        	$filter->addStreamType(true);
        }
        
        if($type == 'slotStrengthen'){
        	$filter->addSlot(true);
        }
        
        if($type == 'equipWear'){
        	$filter->addSlot(true);
        	$filter->addWeartype(true);
        }
        
        if($type == 'equipInlay'){
        	$filter->addSlot(true);
        }
        
        if($type == 'equipSuit'){
        	$filter->addSlot(true);
        	$filter->addSuitType(true);
        }
        
        if($type == 'rank'){
        	$filter->addRankType(false);
        }
        
        if($type == 'email'){
        	$filter->addFilter('mail_title', 'input', '邮件标题');
        }
        
        if($type == 'bossFall' || $type == 'pickup' || $type == 'compose' || $type == 'equipSell' || $type == 'equipSwallow' || $type == 'slotStrengthen' || 
        		$type == 'equipSuit' || $type == 'runeUpgrade' || $type == 'appearanceUpgrade' || $type == 'shapeOpen' || $type == 'shapeUpgrade'){
        	//物品品质帅选
        	$colorType = LogService::getcolorType();
        	$colorType = array('' => '所有') + $colorType;
        	$filter->addFilter('quality', 'select', PubFunc::t('物品品质'), array('options' => $colorType, 'value' => key($colorType)));
        	 
        	$filter->addFilter('g_name', 'input', '物品名称');
        	$filter->addFilter('stage', 'input', '物品阶数');
        	$filter->addFilter('star', 'input', '物品星级');
        }
        
        if($type == 'market'){
        	$filter->addCoin(true);
        }

        $this->setTitle($title);
        
        
        $params = $filter->get();
        
        if($type != 'rank'){
        	$log_s = PubRequest::R('log_s');
        	if(isset($log_s)){
        		$params_s = array();
        		$params_s['special_id'] = $params['special_id'];
        		$params_s['os'] = $params['os'];
        		$params_s['server'] = $params['server'];
        		$params_s['port'] = $params['port'];
        		$params_s['time'] = $params['time'];
        		$params_s['time_start'] = $params['time_start'];
        		$params_s['time_end'] = $params['time_end'];
        		PubAuthSession::set('params_s',$params_s);
        	}else{
        		//echo '第一次';
        		$params_s = PubAuthSession::get('params_s');
        		if(isset($params_s)){
        			$params['special_id'] = $params_s['special_id'];
        			$params['os'] = $params_s['os'];
        			$params['server'] = $params_s['server'];
        			$params['port'] = $params_s['port'];
        			$params['time'] = $params_s['time'];
        			$params['time_start'] = $params_s['time_start'];
        			$params['time_end'] = $params_s['time_end'];
        		}
        		 
        	}
        	$params['log_s'] = 1;
        }
        
        
        $options = PubAuthSession::get('os');
        $os_array = array();
        foreach ($options as $key=>$val){
        	$os_array[] = $key;
        }
        $user = AccAuth::me();
        if($user['IsViewAll'] == 1){
        	$os_array['ALL'] = 'ALL';
        }
        if(!in_array($params['os'], $os_array) && $params['os'] != 'ALL' ){
        	unset($params['os']);
        }


        if($filter->isExport()){
            ini_set('memory_limit','1024M');
            $data   = LogService::data($type, $params, true);
            LibExcel::exportCsv($header, $data, "Mango数据后台-{$title}({$params['time']}).csv");
            exit();
        }else if(PubFunc::isAjax()){
            $result = LogService::data($type, $params);
            $this->out = array(
                'count'     => $result['count'],
                'data'      => $result['data'],
                'result'    => true
            );
            $this->outType = 'json';
        }else{
            $order  = 'ctime';
            $sort = 'desc';
            if($type == 'rank'){
            	$order = 'rank';
            	$sort = 'asc';
            }

            $url = PubFunc::ajaxUrl("?r=log/{$type}", $params);
            $grid->addGrid($header, $url, array('name'=>'数据','order'=>array($order, $sort),'type'=>'log/'.$type,'length'=>50));   

            $this->out['grid'] = $grid->show();
            $this->out['filter'] = $filter->show();
            
            $this->out['is_log'] = 1;
            $this->tpl = 'log.tpl';
        }
    }
} 
